package com.dkd.common.zUtils;

import com.dkd.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Component
public class ZThreadPool {
    @Autowired
    RedisCache redisCache;

    private final ScheduledExecutorService executor =
            Executors.newScheduledThreadPool(5);

    //延迟线程池
    public int ScheduledThreadPool(String key, long delay, TimeUnit unit) {
        executor.schedule(() -> {
            redisCache.deleteObject(key);
        }, delay, unit);
        return 1;
    }

}
